class Rotate2 extends egret.DisplayObjectContainer {
    private ball: Ball
    private vr: number = 0.05
    private cos: number = Math.cos(this.vr)
    private sin: number = Math.sin(this.vr)

    public constructor() {
        super()
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this)
    }

    private onAddToStage(event: egret.Event) {
        this.ball = new Ball()
        this.addChild(this.ball)
        this.ball.x = Math.random() * this.stage.stageWidth
        this.ball.y = Math.random() * this.stage.stageHeight
        this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this)
    }

    private onEnterFrame(event:Event) {
        let x1: number = this.ball.x - this.stage.stageWidth / 2
        let y1: number = this.ball.y - this.stage.stageHeight / 2
        let x2: number = this.cos * x1 - this.sin * y1
        let y2: number = this.cos * y1 + this.sin * x1
        this.ball.x = this.stage.stageWidth / 2 + x2
        this.ball.y = this.stage.stageHeight / 2 + y2
    }
}